package com.health.work.utils;

import com.health.work.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.widget.EditText;

public class TipsUtil {

	public static void showAlert(Context mContext, String title, String message) {
		if (title != null) {

		} else {
			title = mContext.getString(R.string.errorTitle);
		}
		Dialog alertDialog = new AlertDialog.Builder(mContext).setTitle(title)
				.setMessage(message)
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create();
		alertDialog.show();
	}

	public static void showForwordTips(final Activity mContext, String title,
			String message) {
		if (title != null) {

		} else {
			title = mContext.getString(R.string.errorTitle);
		}
		Dialog alertDialog = new AlertDialog.Builder(mContext)
				.setTitle(title)
				.setMessage(message)
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent();
						intent.setAction("android.intent.action.VIEW");
						Uri content_url = Uri.parse("http://www.yihuquan.com");
						intent.setData(content_url);
						intent.setClassName("com.android.browser",
								"com.android.browser.BrowserActivity");
						mContext.startActivity(intent);
						dialog.cancel();
					}
				})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create();
		alertDialog.show();
	}

	public static void showAlertFinish(final Activity mContext, String title,
			String message) {
		if (title != null) {

		} else {
			title = mContext.getString(R.string.errorTitle);
		}
		Dialog alertDialog = new AlertDialog.Builder(mContext).setTitle(title)
				.setMessage(message)
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						mContext.finish();
						dialog.cancel();
					}
				}).create();
		alertDialog.show();
	}

	public static void showExit(final Activity mActivity) {
		Dialog alertDialog = new AlertDialog.Builder(mActivity)
				.setTitle(R.string.errorTitle)
				.setMessage("您确定要退出吗？")
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						SharedPreferences pre = mActivity.getSharedPreferences(
								HEALTHPASSPORT.USERINFO, 0);
//						pre.edit().clear().commit();
						pre.edit().remove(HEALTHPASSPORT.ID)
						.remove(HEALTHPASSPORT.IDNUMBER)
						.remove(HEALTHPASSPORT.INTERGRAL)
						.remove(HEALTHPASSPORT.NAME).commit();
						dialog.cancel();
						mActivity.finish();
					}
				})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create();
		alertDialog.show();
	}

	public static boolean isNull(EditText e){
		if(e.getText()!=null && e.getText().toString().length()>0){
			return false;
		}else{
			return true;
		}
	}
	
	public static boolean isNull(String e){
		if(e!=null && e.length()>0){
			return false;
		}else{
			return true;
		}
	}
}
